package view.hall
{
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import model.hall.ListData;
	
	import utils.DisplayTool;
	import utils.TextTool;
	
	import view.components.RemoteHtmlImg;
	import view.components.RemoteImage;
	
	public class ListItem extends Sprite
	{
		private var nameText:TextField;
		private var moneyText:TextField;
		private var stateText:TextField;
		private var remoteImg:RemoteHtmlImg;
		private var _selected:Boolean;
		private var _data:ListData;
		
		public function ListItem()
		{
			this.mouseChildren = false;
			initTexts();
			initFace();
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(v:Boolean):void
		{
			_selected = v;
		}

		public function drawOutBg():void
		{
			if (_selected)
			{
				with(this.graphics)
				{
					clear();
					beginFill(0xFFFFFF,.4);
					drawRect(0,0,width,height);
					endFill();
				}
			}
			else
			{
				this.graphics.clear();
			}
		}
		
		public function drawOverBg():void
		{
			with(this.graphics)
			{
				clear();
				if (_selected)
				{
					beginFill(0xFFFFFF,.6);
				}
				else
				{
					beginFill(0xFFFFFF,.3);
				}
				drawRect(0,0,width,height);
				endFill();
			}
		}
		
		public function drawSelectBg():void
		{
			with(this.graphics)
			{
				clear();
				beginFill(0xFFFFFF,.6);
				drawRect(0,0,width,height);
				endFill();
			}
		}
		
		private function initFace():void
		{
			remoteImg = new RemoteHtmlImg(45,45);
			remoteImg.x = 2;
			addChild(remoteImg);
		}
		
		private function initTexts():void
		{
			nameText = TextTool.getTextField(100,20,12,0xFFFFFF,false,true);
			nameText.x = 64;
			addChild(nameText);
			
			moneyText = TextTool.getTextField(100,20,12,0xFFFF00,false,true);
			moneyText.x = 64;
			moneyText.y = 12;
			addChild(moneyText);
			
			stateText = TextTool.getTextField(100,20,12,0xFF6600);
			stateText.x = 64;
			stateText.y = 24;
			addChild(stateText);
		}
		
		public function update(listData:ListData):void
		{
			nameText.text = listData.userName;
			moneyText.text = "$" + listData.money;
			stateText.text = listData.state;
			remoteImg.loadImg(listData.headImg);
			_data = listData;
		}
		
		public function get data():ListData
		{
			return _data;
		}
		
		public function destroy():void
		{
			nameText = null;
			moneyText = null;
			stateText = null;
			remoteImg.destroy();
			remoteImg = null;
			_data = null;
			DisplayTool.removeAllChild(this);
		}
	}
}